﻿using FineUI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.JoinParty;
using ZHDJ.JoinParty.BLL;
using ZHDJ.WebPage;

namespace JoinParty.admin.ProcessSetting
{
    public partial class ProcessEdit : PageBase
    {
        #region 页面属性
        public string ID
        {
            get
            {
                if (Request.QueryString["ID"] != null)
                {
                    return Request.QueryString["ID"].ToString();
                }
                return Guid.NewGuid().ToString("N");
            }
        }

        public string EditorContent { get; set; }

        #endregion
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "CoreUserEdit";
            }
        }

        #endregion

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
                LoadData();
            }
        }
        private void BindData()
        {

            btnClose.OnClientClick = ActiveWindow.GetHideReference();

        }

        private void LoadData()
        {
            var pro = DB.PartyJoinProcesss.Find(ID);
            
            if (pro == null)
            {
                Alert.Show("参数错误！", String.Empty);
                return;
            }
            else
            {
                txtProcessName.Text = pro.ProcessName;
                heContent.Text = pro.WorkPoint;
                this.cbIsNeetMessage.Checked = pro.IsSendMassage;
                var proS = DB.PartyJoinProcesss.Where(a => a.StepNo < pro.StepNo).OrderBy(a => a.StepNo);
                ControlBusiness.ControlBind(ddlback, proS, "ProcessName", "ID", true);

                ddlback.SelectedValue = pro.BackToStepID ?? "";
            }
        }
        #endregion

        #region Events

        protected void btnSaveClose_Click(object sender, EventArgs e)
        {
            var pro = DB.PartyJoinProcesss.Find(ID);
            if (pro != null)
            {
                pro.ProcessName = txtProcessName.Text;
                pro.BackToStepID = ddlback.SelectedValue;
                pro.WorkPoint = this.heContent.Text;
                pro.IsSendMassage = this.cbIsNeetMessage.Checked;
                DB.SaveChanges();
            }
            else
            {
                Alert.Show("参数错误！", String.Empty);
            }
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }

        #endregion
    }
}